﻿using System;
using System.Collections.Generic;
using System.Windows;

namespace CharacterModel.Extensions
{
    public static class PointEnumerableExtensions
    {
        public static Rect BoundingRectangle(this IEnumerable<Point> points)
        {
            double minX = double.MaxValue, minY = double.MaxValue, maxX = double.MinValue, maxY = double.MinValue;

            foreach (var point in points)
            {
                minX = Math.Min(minX, point.X);
                minY = Math.Min(minY, point.Y);
                maxX = Math.Max(maxX, point.X);
                maxY = Math.Max(maxY, point.Y);
            }

            return new Rect(new Point(minX, minY), new Point(maxX, maxY));
        }
    }
}
